<?php
namespace Admin\Models\sys;

use Phalcon\Di;
use Helpers\CurlClient as HttpClient;
use Admin\Models\InterfaceService;

/**
 * Class Dictionaries 字典
 * @package Admin\Models\Question
 */
class PowerTree extends InterfaceService
{
    private static $interfaceKey = '';
    const  WRITE_NEW = 'http://s.xh.com/api/Powertree/writeNew';//权限写入新数据库

    /**
     * #方法说明：题库数据层
     * # Created by wy
     */
    public function initialize()
    {
        parent::initialize();
    }

    /**
     * #方法说明：创建httpUrl
     * @param $httpUrl
     * @param array $paramArr
    # Created by wy
     */
    public static function createHttpUrl($httpUrl, $paramArr = array())
    {
        return parent::createInterfaceUrl($httpUrl, $paramArr, self::$interfaceKey);
    }

    /**
     * #方法说明：权限写入新数据库
     * @param array $paramArr
     * @param array $urlArr
     * @return array|bool|mixed|string
    # Created by wy
     */
    public function writeNew($paramArr = array(), $urlArr = array())
    {
        $http = new HttpClient();
        $http->setBaseUrl(self::createHttpUrl(self::WRITE_NEW, $urlArr));
        $result = $http->json(null, $paramArr)->headerConvert();
        if (in_array($result['statusCode'], [200, 201, 204])) {
            return $http->bodyConvert();
        } else {
            return array();
        }
    }
}